/**
 * Copyright (C), 2018-2018, 孙春磊有限公司
 * FileName: UserServiceImpl
 * Author:   Administrator
 * Date:     2018/11/1 15:04
 * Description:
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.yh.service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.yh.dao.UserDao;
import com.yh.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 〈一句话功能简述〉<br> 
 * 〈〉
 *
 * @author Administrator
 * @create 2018/11/1
 * @since 1.0.0
 */
@Service("userService")
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    public UserDao getUserDao() {
        return userDao;
    }

    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }


    @Override
    public Page queryLikeUsers(Map<String, Object> map) {
        Page page = new Page();
        //得到总记录数，付给page的相关属性
        page.setTotal(userDao.getLikeUsersCount(map));
        //得到每页的大小
        int pageSize = Integer.parseInt(String.valueOf(map.get("pageSize")));
        page.setPageSize(pageSize);
        //得到当前页码
        int curPageNum = Integer.parseInt(String.valueOf(map.get("pageNum")));
        //计算出总页数
        page.setPageNum((int) (page.getTotal() / pageSize + (page.getTotal() % pageSize == 0 ? 0 : 1)));
        //启用分页
        page = PageHelper.startPage(curPageNum, pageSize);
        //查询列表
        List list = userDao.getLikeUsers(map);
        return page;
    }

    @Override
    public Integer addUser(User user) {
        return userDao.addUser(user);
    }

    public Integer delUser(Integer userId){
        return userDao.delUser(userId);

    }
    @Override
    public User getUserById(Integer userId) {
        return userDao.getUserById(userId);
    }

    @Override
    public Integer updateUser(User user) {
        return userDao.updateUser(user);
    }

}
